home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / tex / dvi / dvipssrc.zoo / dopage.c < prev    next >
C/C++ Source or Header  |  1991-01-26  |  11KB  |  347 lines

  1. /*
  2.  *   Main page drawing procedure.  Interprets the page commands.  A simple
  3.  *   (if lengthy) case statement interpreter.  
  4.  */
  5. #include "structures.h" /* The copyright notice in that file is included too! */
  6. #include <math.h>
  7. /*
  8.  *   The external routines we use:
  9.  */
  10. extern void error() ;
  11. extern void pageinit() ;
  12. extern void drawrule() ;
  13. extern shalfword dvibyte() ;
  14. extern halfword twobytes() ;
  15. extern integer threebytes() ;
  16. extern integer signedquad() ;
  17. extern shalfword signedbyte() ;
  18. extern shalfword signedpair() ;
  19. extern integer signedtrio() ;
  20. extern void dospecial() ;
  21. extern void drawchar() ;
  22. extern integer scalewidth() ;
  23. extern void skipover() ;
  24. #ifndef XENIX
  25. extern double floor() ;
  26. #endif
  27. extern void fontdef() ;
  28. extern void pageend() ;
  29. /*
  30.  *   Now the external variables.
  31.  */
  32. extern fontdesctype *curfnt ;
  33. extern fontdesctype *baseFonts[] ;
  34. extern fontmaptype *ffont ;
  35. extern quarterword *curpos, *curlim ;
  36. extern integer hh, vv ;
  37.  
  38. /*
  39.  * CONVENTION:  conv -> horizontial converter
  40.  *        vconv -> vertical converter
  41.  */
  42. extern real conv ;
  43. extern real vconv ;
  44.  
  45. extern FILE *bitfile ;
  46. extern int actualdpi ;
  47. extern int vactualdpi ;
  48. extern frametype frames[] ;
  49. extern int maxdrift ;
  50. extern int vmaxdrift ;
  51. #ifdef EMTEX
  52. extern void emclear() ;
  53. #endif
  54.  
  55. #ifdef XENIX
  56. #define PixRound(x) ((integer)(x + (iconv >> 1)) / iconv)
  57. #define VPixRound(x) ((integer)(x + (viconv >> 1)) / viconv)
  58. #else
  59. #define PixRound(x) ((integer)(floor(((x) * conv) + 0.5)))
  60. #define VPixRound(x) ((integer)(floor(((x) * vconv) + 0.5)))
  61. #endif
  62. /*
  63.  *   Now we have the dopage procedure.
  64.  *   Most error checking is suppressed because the prescan has already
  65.  *   verified that the DVI data is OK....except for stack over/underflow.
  66.  */
  67. static struct dvistack {
  68.   integer hh, vv ;
  69.   integer h, v, w, x, y, z ;
  70. } stack[STACKSIZE] ;
  71. void
  72. dopage()
  73. {
  74.    register shalfword cmd ;
  75.    register integer p ;
  76.    register chardesctype *cd ;
  77.    register integer h ;
  78.    register fontmaptype *cfnt ;
  79.    register frametype *frp = frames ;
  80.    integer fnt ;
  81.    int charmove ;
  82.    struct dvistack *sp = stack ;
  83.    integer v, w, x, y, z ;
  84.    integer roundpos ;
  85.    integer thinspace ;
  86.    integer vertsmallspace ;
  87. #ifdef XENIX
  88.    integer iconv ;
  89.    integer viconv ;
  90.  
  91.    iconv = (integer)(1.0 / conv + 0.5) ;
  92.    viconv = (integer)(1.0 / vconv + 0.5) ;
  93. #endif
  94. #ifdef EMTEX
  95.    emclear() ;
  96. #endif
  97.    pageinit() ;
  98.  
  99.    thinspace =  (integer)(0.025*DPI/conv) ; /* 0.025 inches */
  100.    vertsmallspace = (integer)(0.025*VDPI/vconv) ; /* 0.025 inches */
  101.  
  102.    hh = vv = h = v = w = x = y = z = 0 ;
  103.    curfnt = NULL ;
  104.    curpos = NULL ;
  105.    charmove = 0 ;
  106. beginloop:
  107.    switch (cmd=dvibyte()) {
  108. case 138: goto beginloop ; /* nop command does nuttin */
  109. /*
  110.  *   For put1 commands, we subtract the width of the character before
  111.  *   dropping through to the normal character setting routines.  This
  112.  */
  113. case 133: /* put1 */
  114.    cmd = dvibyte() ;
  115.    charmove = 0 ;
  116.    goto dochar ;
  117. case 128: cmd = dvibyte() ; /* set1 command drops through to setchar */
  118. default: /* these are commands 0 (setchar0) thru 127 (setchar127) */
  119.    charmove = 1 ;
  120. dochar:
  121.    cd = &(curfnt->chardesc[cmd]) ;
  122.    if (cd->flags & EXISTS) {
  123.       if (curfnt->loaded == 2) { /* virtual character being typeset */
  124.          if (charmove) {
  125.             sp->hh = hh + cd->pixelwidth ; sp->vv = vv ;
  126.             sp->h = h + cd->TFMwidth ; sp-> v = v ;
  127.          } else {
  128.             sp->hh = hh ; sp->h = h ;
  129.          }
  130.          sp->vv = vv ; sp-> v = v ;
  131.          sp->w = w ; sp->x = x ; sp->y = y ; sp->z = z ;
  132.          if (++sp >= &stack[STACKSIZE]) error("! Out of stack space") ;
  133.          w = x = y = z = 0 ; /* will be in relative units at new stack level */
  134.          frp->curp = curpos ;
  135.          frp->curl = curlim ;
  136.          frp->ff = ffont ;
  137.          frp->curf = curfnt ;
  138.          if (++frp == &frames[MAXFRAME] )
  139.             error("! virtual recursion stack overflow") ;
  140.          curpos = cd->packptr + 2 ;
  141.          curlim = curpos + (256*(long)(*cd->packptr)+(*(cd->packptr+1))) ;
  142.          ffont = curfnt->localfonts ;
  143.          if (ffont) {
  144.             curfnt = ffont->desc ;
  145.             thinspace = curfnt->thinspace ;
  146.          } else {
  147.             curfnt = NULL ;
  148.             thinspace = vertsmallspace ;
  149.          }
  150.          goto beginloop ;
  151.       }
  152.       drawchar(cd, cmd) ;
  153.    }
  154.    if (charmove) {
  155.       h += cd->TFMwidth ;
  156.       hh += cd->pixelwidth ;
  157.    }
  158.    goto setmotion ;
  159. case 129: case 130: case 131: case 134: case 135: case 136: case 139: 
  160. case 247: case 248: case 249: case 250: case 251: case 252: case 253:
  161. case 254: case 255: /* unimplemented or illegal commands */
  162.    error("! synch") ;
  163. case 132: case 137: /* rules */
  164.  { integer ry, rx , rxx, ryy ;
  165.    ry = signedquad() ; rx = signedquad() ;
  166.    if (rx>0 && ry>0) {
  167.       if (curpos) {
  168.          rx = scalewidth(rx, (frp-1)->curf->scaledsize) ;
  169.          ry = scalewidth(ry, (frp-1)->curf->scaledsize) ;
  170.       }
  171.       rxx = (int)(conv * rx + 0.9999999) ;
  172.       ryy = (int)(vconv * ry + 0.9999999) ;
  173.       drawrule(rxx, ryy) ;
  174.    } else
  175.       rxx = 0 ;
  176.    if (cmd == 137) goto beginloop ;
  177.    h += rx ; hh += rxx ;
  178.    goto setmotion ;
  179.  }
  180. case 141: /* push */
  181.    sp->hh = hh ; sp->vv = vv ; sp->h = h ; sp->v = v ;
  182.    sp->w = w ; sp->x = x ; sp->y = y ; sp->z = z ;
  183.    if (++sp >= &stack[STACKSIZE]) error("! Out of stack space") ;
  184.    goto beginloop ;
  185. case 140: /* eop or end of virtual character */
  186.    if (curpos == NULL) break ; /* eop */
  187.    --frp ;
  188.    curfnt = frp->curf ;
  189.    thinspace = (curfnt) ? curfnt->thinspace : vertsmallspace ;
  190.    ffont = frp->ff ;
  191.    curlim = frp->curl ;
  192.    curpos = frp->curp ;
  193.    if (hh < (sp-1)->hh+2 && hh > (sp-1)->hh-2)
  194.       (sp-1)->hh = hh; /* retain `intelligence' of pixel width, if close */ 
  195.    /* falls through */
  196. case 142: /* pop */
  197.    if (--sp < stack) error("! More pops than pushes") ;
  198.    hh = sp->hh ; vv = sp->vv ; h = sp->h ; v = sp->v ;
  199.    w = sp->w ; x = sp->x ; y = sp->y ; z = sp->z ;
  200.    goto beginloop ;
  201. case 143: /* right1 */
  202.    p = signedbyte() ; goto horizontalmotion ;
  203. case 144: /* right2 */
  204.    p = signedpair() ; goto horizontalmotion ;
  205. case 145: /* right3 */
  206.    p = signedtrio() ; goto horizontalmotion ;
  207. case 146: /* right4 */
  208.    p = signedquad() ; goto horizontalmotion ;
  209. case 147: /* w0 */
  210.    p = w ; goto horizontalmotion ;
  211. case 148: /* w1 */
  212.    p = w = signedbyte() ; goto horizontalmotion ;
  213. case 149: /* w2 */
  214.    p = w = signedpair() ; goto horizontalmotion ;
  215. case 150: /* w3 */
  216.    p = w = signedtrio() ; goto horizontalmotion ;
  217. case 151: /* w4 */
  218.    p = w = signedquad() ; goto horizontalmotion ;
  219. case 152: /* x0 */
  220.    p = x ; goto horizontalmotion ;
  221. case 153: /* x1 */
  222.    p = x = signedbyte() ; goto horizontalmotion ;
  223. case 154: /* x2 */
  224.    p = x = signedpair() ; goto horizontalmotion ;
  225. case 155: /* x3 */
  226.    p = x = signedtrio() ; goto horizontalmotion ;
  227. case 156: /* x4 */
  228.    p = x = signedquad() ; goto horizontalmotion ;
  229. case 157: /* down1 */
  230.    p = signedbyte() ; goto verticalmotion ;
  231. case 158: /* down2 */
  232.    p = signedpair() ; goto verticalmotion ;
  233. case 159: /* down3 */
  234.    p = signedtrio() ; goto verticalmotion ;
  235. case 160: /* down4 */
  236.    p = signedquad() ; goto verticalmotion ;
  237. case 161: /* y0 */
  238.    p = y ; goto verticalmotion ;
  239. case 162: /* y1 */
  240.    p = y = signedbyte() ; goto verticalmotion ;
  241. case 163: /* y2 */
  242.    p = y = signedpair() ; goto verticalmotion ;
  243. case 164: /* y3 */
  244.    p = y = signedtrio() ; goto verticalmotion ;
  245. case 165: /* y4 */
  246.    p = y = signedquad() ; goto verticalmotion ;
  247. case 166: /* z0 */
  248.    p = z ; goto verticalmotion ;
  249. case 167: /* z1 */
  250.    p = z = signedbyte() ; goto verticalmotion ;
  251. case 168: /* z2 */
  252.    p = z = signedpair() ; goto verticalmotion ;
  253. case 169: /* z3 */
  254.    p = z = signedtrio() ; goto verticalmotion ;
  255. case 170: /* z4 */
  256.    p = z = signedquad() ; goto verticalmotion ;
  257. case 171: case 172: case 173: case 174: case 175: case 176: case 177:
  258. case 178: case 179: case 180: case 181: case 182: case 183: case 184:
  259. case 185: case 186: case 187: case 188: case 189: case 190: case 191:
  260. case 192: case 193: case 194: case 195: case 196: case 197: case 198:
  261. case 199: case 200: case 201: case 202: case 203: case 204: case 205:
  262. case 206: case 207: case 208: case 209: case 210: case 211: case 21